package com.kpijavatraining6.module2.sessionTools;

import com.kpijavatraining6.module2.actionTools.TestStep;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: Vladislav
 * Date: 28.10.13
 * Time: 20:10
 * To change this template use File | Settings | File Templates.
 */
public class History  {
    public final int MAX_LENGTH = 20;
    private ArrayList<TestStep> questions;
    private int currentNumber;
    private int lastExistedNumber;

    public ArrayList<TestStep> getTestStepArr(){
        return questions;
    }

    public History() {
        questions = new ArrayList<TestStep>();
        currentNumber = 0;
        lastExistedNumber = 0;
    }

    public void push(TestStep testStep) {
        questions.add(currentNumber,testStep);
        currentNumber++;
        lastExistedNumber = currentNumber;
    }

    public void rollBack() {
        if(isRollBackPossible()) {
            currentNumber--;
        }
    }

    public boolean isRollBackPossible() {
        if(currentNumber > 0) {
            return true;
        } else {
            return false;
        }
    }
    public TestStep pull() {
        if(isRollBackPossible()) {
            currentNumber--;
            return questions.get(currentNumber);
        }
        else {
            return questions.get(currentNumber);
        }
    }
    public void goForward() {
        if(isGoForwardPossible()) {
            currentNumber++;
        }
    }
    public boolean isGoForwardPossible(){
        if(currentNumber < lastExistedNumber) {
            return true;
        } else {
            return false;
        }
    }
    public int getCurrentNumber() {
        return currentNumber;
    }

}
